package wwek6;

import java.util.Arrays;
import java.util.Scanner;

 interface IntegerStack {
	public abstract Integer push(Integer item);
	public abstract Integer pop();   
	public abstract Integer peek(); 
	public abstract boolean empty(); 
	public abstract int size();      
}

class ArrayIntegerStack implements IntegerStack{
	private Integer []a;
	private  int top=-1;
	public ArrayIntegerStack(int n) {
		this.a=new Integer[n];
	}
	
	public Integer[] getA() {
		return a;
	}
	public Integer push(Integer item) {
		// TODO Auto-generated method stub
		if(top==a.length-1)
			return null;
		else if(top<a.length-1 && item==null) {
			return null;
		}
		else if(top<a.length-1 && item!=null) {
			top++;
			a[top]=item;
			return item;
		}
		return item;
	}
	public Integer pop() {
		// TODO Auto-generated method stub
		if(top==-1)
			return null;
		else {
			top--;
			return a[top+1];
		}
	}
	public Integer peek() {
		// TODO Auto-generated method stub
		if(top==-1)
		return null;
		else return a[top];
	}

	public boolean empty() {
		// TODO Auto-generated method stub
		if(top==-1)
			return true;
		return false;
	}

	public int size() {
		// TODO Auto-generated method stub
		return top+1;
	}
	
}
public class PTA720403 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		ArrayIntegerStack stack=new ArrayIntegerStack(n);
		int m = Integer.parseInt(in.nextLine());
		for(int i=0;i<m;i++) {
			System.out.println(stack.push(in.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(Arrays.toString(stack.getA()));
		int x=in.nextInt();
		for(int i=0;i<x;i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(Arrays.toString(stack.getA()));
		
	}

}
